package main

import (
	"errors"
	"fmt"
	"math"
)

func main() {
	sqrt, err := MySqrt(3)
	if err == nil {
		fmt.Println("非命名函数：", sqrt)
	}

	sqrt, err = MySqrt2(-1)
	if err == nil {
		fmt.Println("命名函数：", sqrt)
	}
	fmt.Println("命名函数：", err)
}

func MySqrt(a float64) (float64, error) {
	if a < 0 {
		return 0, errors.New("参数必须大于0")
	}
	return math.Sqrt(a), nil
}

func MySqrt2(a float64) (r float64, err error) {
	if a < 0 {
		err = errors.New("参数必须大于0")
		return
	}
	r = math.Sqrt(a)
	return
}
